<template>
  <div class="customer-info">
    <div class="back" @click="backHome">首页</div>

    <div class="search-box">
      <ComSearchInput />
    </div>

    <div class="info-box" v-loading="loading">
      <div class="info-list">
        <div class="info-item" v-for="(item, index) of customerData" :key="index" @click="toDetail(item)">
          <div class="item-header">
            <div class="item-info">
              <el-avatar :size="30" :src="getLogo(item.logo)" />
              <div class="name">{{ item.zhName }}</div>
            </div>
          </div>
          <div class="item-main">
            <p>简称：{{item.zhShortName}}</p>
            <div class="intro" v-html="item.briefIntro"></div>
          </div>
        </div>
      </div>
      <el-empty v-if="!customerData.length" description="暂无数据"></el-empty>
    </div>

    <div class="release-btn" @click="addCustomer"></div>
  </div>
</template>
<script setup lang="ts">
import { defineComponent, ref } from "vue";
import ComSearchInput from "../../components/comSearchInput/index.vue";
import { useRouter } from "vue-router";
import { customList } from "@/api/customerInfo";
import { ICustomerInfo } from "@/api/customerInfo/type";
import {getLogo} from "@/utils";


const router = useRouter();
const customerData = ref<ICustomerInfo[]>([]);
const loading = ref(false);

function backHome() {
  router.push("pageHome");
}

function toDetail(item: any) {
  router.push({
    name: "customerInfoDetail",
    query: { id: item.id }
  });
}

function addCustomer() {
  router.push({name: "customerInfoDetail",});
}

function getCustomList() {
  loading.value = true;
  customList().then((res) => {
    customerData.value = res.rows || [];
  }).finally(() => loading.value = false);
}

getCustomList();

defineComponent({ name: "CustomerInformation" });
</script>

<style scoped lang="scss">
.customer-info {
  position: relative;
  width: 100%;
  height: 100%;
  padding-top: 80px;

  .back {
    position: relative;
    margin-top: 20px;
    padding-left: 40px;
    color: #FF4350;
    cursor: pointer;

    &::before {
      content: '';
      display: inline-block;
      position: absolute;
      top: 50%;
      left: 10px;
      width: 20px;
      height: 12px;
      background: url('../../assets/arrow.png') no-repeat center;
      transform: translateY(-50%) scaleX(-1);
    }
  }

  .search-box {
    margin: 36px 0 10px 0;
    padding: 0 85px 0 55px;
  }

  .time-filter {
    width: 100%;
    height: 70px;
    padding: 0 265px;
    display: flex;
    justify-content: space-between;
    background-color: #F9F9F9;

    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      p:first-child {
        margin-bottom: 8px;
        color: #999;
      }

      p:nth-child(2) {
        font-size: 18px;
        color: #2e3244;
        font-weight: bold;
      }
    }
  }

  .info-box {
    position: relative;
    width: 100%;
    margin-top: 10px;
    padding: 15px;
    background: #fff;

    .info-list {
      //width: 100%;
      display: flex;
      flex-wrap: wrap;

      .info-item {
        position: relative;
        width: calc((100% - 32px) / 3);
        height: 206px;
        margin-right: 16px;
        margin-bottom: 16px;
        padding: 0 10px;
        background-color: #f9f9f9;
        cursor: pointer;

        &:nth-child(3n) {
          margin-right: 0;
        }

        .item-header {
          width: 100%;
          height: 60px;
          padding-left: 10px;
          padding-right: 20px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 16px;
          color: #2E3244;
          border-bottom: 1px solid rgba(187, 187, 187, 0.5);

          .item-info {
            width: 100%;
            display: flex;
            align-items: center;

            .el-avatar {
              margin-right: 10px;
            }

            .name {
              width: calc(100% - 80px);
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
        }

        .item-main {
          padding: 10px;
          font-size: 14px;
          overflow: hidden;

          .intro {
            margin-top: 10px;
            display: -webkit-box;
            word-break: break-all;
            text-overflow: ellipsis;
            overflow: hidden;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
          }
        }
      }
    }

    .page-box {
      width: calc(100% - 172px);
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: absolute;
      left: 86px;
      bottom: 25px;
      font-size: 16px;
      background: rgba(255, 255, 255, 0.43);
      box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
      border-radius: 8px;
      backdrop-filter: blur(10px);

      .jump-btn {
        cursor: pointer;
      }

      .page-main {
        margin: 0 15px;

        .page-item {
          margin-right: 15px;
          color: #bfbfbf;
          cursor: pointer;

          &.active {
            color: #2E3244;
          }

          &:last-child {
            margin-right: 0;
          }
        }
      }
    }
  }

  .release-btn {
    position: fixed;
    right: 100px;
    bottom: 200px;
    width: 92px;
    height: 92px;
    background: url('./assets/release.png') no-repeat center;
    cursor: pointer;
  }
}
</style>
